﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace SecureCookie.Implementation.Protocol.Impl
{
    /// <summary>
    /// Implementation for <see cref="IRequestState"/> that uses the Item statebag from <see cref="HttpContext"/>
    /// </summary>
    class RequestStateFromHttpContextItems : IRequestState
    {
        private const string KEY_PREFIX = "SecureCookieHttpModule.Expiration.";

        public bool HasExpirationFromIncomingCookie(string cookieName)
        {
            return HttpContext.Current.Items.Contains(KEY_PREFIX + cookieName);
        }

        public DateTime ExpirationFromIncomingCookie(string cookieName)
        {
            return (DateTime)HttpContext.Current.Items[KEY_PREFIX + cookieName];
        }

        public void RegisterExpirationFromIncomingCookie(DateTime dateTime, string cookieName)
        {
            HttpContext.Current.Items[KEY_PREFIX + cookieName] = dateTime;
        }
    }
}
